|
|
|
|
|
|
|
The picture box on the right contains a bitmap that defines a rainbow selection of different colors. When the program fills this box, Visual Basic selects the color in the picture box's palette that is closest to the specified color. While these colors are not dithered, they usually do not match the color you request exactly. |
|
|
|
|
|
|
|
|
Example program Custom, shown in Figure 3.5, displays colors using static colors and a customized color palette. Whenever you select a new color value, the program modifies the right picture box's color palette so that it can display exactly the color you select. In Figure 3.5, Visual Basic has dithered using white dots on dark gray to produce a slightly lighter shade of gray in the left picture box. |
|
|
|
|
|
|
|
|
There are two ways you can specify a color in a logical palette. First, you can specify the index of the color. To do this, add &H1000000 to the index of the color you want and pass the result to the Visual Basic drawing routine. For instance, the following code fills a box using the color in position 72 in the logical palette: |
|
|
|
 |
|
|
|
|
Line (0, 0)(50, 50), 72 + &H1000000, BF |
|
|
|
|
|
|
|
|
Visual Basic automatically translates the color value 72 + &H1000000 into whatever value is in position 72 in the logical palette. |
|
|
|
|
|
|
|
|
Example program LogIndex, shown in Figure 3.6, uses this technique to display the colors in a logical palette. Choose an image file by selecting Open from the File menu. The program loads the image into the left picture box. It then uses the following statements to make the right picture box use the same palette as the left picture box. |
|
|
|
 |
|
|
|
|
picPalette.Picture = picPalette.Image
picPalette.Picture.hPal = picBitmap.Picture.hPal |
|
|
|
|
|
|
|
|
Figure 3.5
Example program Custom displays colors using
static colors and a customized palette. |
|
|
|
|
|